package com.pwr.app.characteristics;

import java.text.DecimalFormat;

public class HistogramCharacteristics implements BaseCharacteristics {

	@Override
	public double[] computeCharacteristics(boolean[][] image, int sampleRectDim) {
		sampleRectDim = sampleRectDim / 2;
		double[] toReturn = new double[sampleRectDim + sampleRectDim];
		sampleRectDim = image.length / sampleRectDim;
		double toSave = 0;
		for (int i = 0; i < image[0].length; i++) {
			double sumColumnY = 0;
			for (int l = 0; l < image.length; l++) {
				if (image[l][i])
					sumColumnY++;
			}
			toSave += sumColumnY;
			if ((i + 1) % sampleRectDim == 0) {
				if ((i + 1) / sampleRectDim - 1 < toReturn.length)
					toReturn[(i + 1) / sampleRectDim - 1] = toSave / (double) (image[i].length * sampleRectDim);
				toSave = 0;
			}
		}

		for (int i = 0; i < image.length; i++) {
			double sumRowX = 0;
			for (int l = 0; l < image[0].length; l++) {
				if (image[i][l])
					sumRowX++;
			}
			toSave += sumRowX;
			if ((i + 1) % sampleRectDim == 0) {
				if (image[0].length / sampleRectDim + (i + 1) / sampleRectDim - 1 < toReturn.length)
					toReturn[image[0].length / sampleRectDim + (i + 1) / sampleRectDim - 1] = toSave / (double) (image[i].length * sampleRectDim);
				toSave = 0;
			}
		}
		return toReturn;
	}
}
